/*
 * @Author: your name
 * @Date: 2020-07-28 22:35:35
 * @LastEditTime: 2021-08-01 22:49:20
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \react-hooks-app\src\compontent\useReucer.js
 */


 import React,{useReducer,useContext} from 'react';

 import {userReducerDemo} from '../reducer.js'
 //import {CountContext} from '../context'

 function UserReducerDemo(){
  //let dataCountContext = useContext(CountContext)
  // function useReducer(reducer, initialState) {
  //   const [state, setState] = useState(initialState);

  //   function dispatch(action) {
  //     const nextState = reducer(state, action);
  //     setState(nextState);
  //   }

  //   return [state, dispatch];
  // }
  const [count,dispatch] = useReducer(userReducerDemo,0)
  return (
    <div>
      <p>现在的状态是{count}</p>
      <button onClick={()=>{dispatch({type:'add'})}}>add</button>
      <button onClick={()=>{dispatch({type:'inc'})}}>inc</button>
    </div>
  );

 }

 export default UserReducerDemo;

